package com.kbt.listener;

import android.app.Activity;
import android.view.View;
import android.widget.Toast;
import com.google.gson.Gson;
import com.kbt.adapter.OrderBaseAdapter;
import com.kbt.commont.Constants;
import com.kbt.model.data.BaseBean;
import com.kbt.model.data.OrderBean;
import com.kbt.model.data.OrderInfoModel;
import com.kbt.net.RequestManager;
import com.kbt.util.utils.SharePreferenceUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhgk
 * @package: com.kbt.listener
 * @TODO: <请描述这个类是干什么的>
 * @data: 2015/8/20 16:29
 * @version: V1.0
 */
public class ClickToPressSendOrderListener implements View.OnClickListener,RequestManager.ResponseInterface{

    private Activity context;
    private List<OrderBean> orderList;
    private OrderBaseAdapter orderAdapter;
    private int position;
    private RequestManager mRequestManager;
    private Map<String, String> map =null;
    private SharePreferenceUtils share;
    private BaseBean baseBean;


    public ClickToPressSendOrderListener(Activity context, List<OrderBean> orderList, OrderBaseAdapter orderWaitPayAdapter, int position) {
        this.context = context;
        this.orderList = orderList;
        this.orderAdapter = orderWaitPayAdapter;
        this.position = position;
        mRequestManager = new RequestManager();
        mRequestManager.setResponseListener(this);
        map = new HashMap<String, String>();
        share = new SharePreferenceUtils(context);
    }

    @Override
    public void onClick(View v) {
        String orderId = orderList.get(position).getOrder_no();
        //催促发货
        httpReqSend();
    }

    @Override
    public <T> void successResponse(T parsedGSON, int tag) {
        if (tag == Constants.RequestTag.reqSendTag) {
            /** 判断返回值不为空 **/
            if (parsedGSON != null) {
                baseBean = (BaseBean) parsedGSON;
                if(baseBean.getResult().equals("success")){
                    Toast.makeText(context,baseBean.getMsg(),Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(context,""+baseBean.getMsg(),Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    @Override
    public void errorResonse(String retmeg, int tag) {
        Toast.makeText(context,""+baseBean.getMsg(),Toast.LENGTH_SHORT).show();
    }
    //催促发货
    private void httpReqSend(){
        map.clear();
        map.put("methodType", "reqSend");
        Gson gson = new Gson();
        Map dataMap = new HashMap<String,String>();
        dataMap.put("order_no",orderList.get(position).getOrder_no());
        dataMap.put("user_mobile", share.getString("user_mobile",""));
        dataMap.put("order_real_je",orderList.get(position).getOrder_real_je());
        map.put("data", gson.toJson(dataMap));
        mRequestManager.post(Constants.ServiceInterFace.reqSendURL, map, Constants.RequestTag.reqSendTag, BaseBean.class);
    }
}
